from typing import Optional
from intelli_port.config import load_settings

_client = None


def get_milvus():
    global _client
    s = load_settings()
    if not s.milvus_uri:
        return None
    if _client is None:
        try:
            from pymilvus import MilvusClient
            _client = MilvusClient(uri=s.milvus_uri)
        except Exception:
            _client = None
    return _client